package com.efounder.form.comp;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.efounder.builder.base.data.DataSetEvent;
import com.efounder.builder.base.data.DataSetListener;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.builder.base.data.ESPRowSet;
import com.efounder.form.DMColComponent;
import com.efounder.form.DMComponent;
import com.efounder.form.DataSetComponent;
import com.efounder.form.base.IComponent;
import com.efounder.form.comp.multiple_images_selector.GalleryActivity;
import com.efounder.form.comp.multiple_images_selector.ViewAdapter;
import com.efounder.form.model.ImageModel;
import com.efounder.form.model.JSONFormModel;
import com.efounder.form.util.CloudUtil;
import com.efounder.form.util.FormCompUtil;
import com.efounder.form.util.ReduseImageUtil;
import com.efounder.frame.ViewSize;
import com.efounder.util.AppContext;
import com.pizidea.imagepicker.AndroidImagePicker;
import com.pizidea.imagepicker.bean.ImageItem;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.efounder.form.util.ReduseImageUtil.chatpath;


/**
 * Created by lch on 16/9/20.
 * 修改宽度、高度需要到adapter里修改
 * 此组件主要参考网上的AndroidImagePicker ，有问题可以查询此资料
 */
public class FormAffixServerButton extends LinearLayout implements IComponent, IUIComponent,
        DMComponent, DMColComponent, GalleryActivity.ImageSelectorRecycleListener, DataSetListener {

    //imageloader的数据集与组件中的dataset区分。
    private ArrayList<ImageModel> imageModelList = new ArrayList<ImageModel>();

    //为了使affix的F_CODE唯一，设置位置标志。
    int f_CodeIndex = 0;
    //基本上下文
    private Context mContext;
    //RecycleView 横向滑动组件
    private RecyclerView recyclerView;
    //设置recycleview 的方向
    private LinearLayoutManager linearLayoutManager;
    //adapter
    private ViewAdapter mAdapter;
    private IUIComponent parentComp;
    private int uploadingNUM = 0;
    private int uploadedNUM = 0;

    public FormAffixServerButton() {
        super(AppContext.getCurrentActivity());
        mContext = AppContext.getCurrentActivity();
    }

    public FormAffixServerButton(Context context) {
        super(AppContext.getCurrentActivity());
        mContext = context;
    }

    public FormAffixServerButton(Context context, AttributeSet attrs) {
        super(AppContext.getCurrentActivity(), attrs);
        mContext = context;
    }

    @Override
    public void creationComplete() {
        initView();
    }

    private void initView() {
        setOrientation(VERTICAL);
        initRecycleView();
    }

    private void initRecycleView() {
        recyclerView = new RecyclerView(getContext());
        this.addView(recyclerView);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup
                .LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.weight = 1;
        recyclerView.setLayoutParams(layoutParams);
        //初始化样式
        linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setPadding(0, 0, 10, 0);

        mAdapter = new ViewAdapter(mContext, imageModelList);

        mAdapter.setImageWidth(this.getViewSize().getHeight());
        mAdapter.setImageHeight(this.getViewSize().getHeight());
        mAdapter.setShowAddButton(isEditAble);
        recyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new ViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, final int position) {
                if (position == imageModelList.size() && isEditAble) {
                    AndroidImagePicker.getInstance().setCurrentSelectedImageSetPosition(0);
                    AndroidImagePicker.getInstance().pickMulti(mContext, true, new
                            AndroidImagePicker.OnImagePickCompleteListener() {
                                @Override
                                public void onImagePickComplete(final List<ImageItem> items) {
                                    if (items != null && items.size() > 0) {
                                        uploadingNUM += items.size();
                                        for (int i = 0; i < items.size(); i++) {
                                            final ImageModel imageModel = new ImageModel();
                                            imageModel.setProgress(0);
                                            final int position1 = i;
                                            final EFRowSet affixObject = new EFRowSet();
                                            new Thread() {
                                                public void run() {
                                                    ReduseImageUtil.saveNewImage(items.get(position1).path, 1920, 1920);
                                                    String savePath = ReduseImageUtil.getFileName(chatpath + ReduseImageUtil.getFileName(items.get(position1).path)) + ".pic";
                                                    //七牛上传需要的路径
                                                    final String imagePath = chatpath + savePath;


                                                    try {

                                                        // mAdapter.notifyDataSetChanged();

                                                        CloudUtil.getCloudRes(imagePath, new CloudUtil.UpLoadListenerWithProgress() {
                                                            @Override
                                                            public void getHttpUrl(Boolean isSuccess, String url) {
                                                                if (isSuccess) {
                                                                    affixObject.put("F_PATH", url);
                                                                    uploadedNUM++;
                                                                } else {
                                                                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                                                                        @Override
                                                                        public void run() {
                                                                            Toast.makeText(mContext, "图片上传失败。", Toast.LENGTH_SHORT).show();
                                                                            imageModel.setProgress(0);
                                                                            mAdapter.notifyDataSetChanged();

                                                                        }
                                                                    });


                                                                }
                                                            }

                                                            @Override
                                                            public void getHttpProgress(int progress) {
                                                                Log.i("上传进度:", String.valueOf(progress));
                                                                imageModel.setProgress(progress);
                                                                mAdapter.notifyDataSetChanged();
                                                            }
                                                        });


//                                                QiNiuUtil.getQiNiuResWithProgress(imagePath, new
//                                                        QiNiuUtil.UpLoadListenerWithProgress() {
//                                                            @Override
//                                                            public void getHttpUrl(Boolean isSuccess, String url) {
//                                                                if (isSuccess) {
//                                                                    affixObject.put("F_PATH", url);
//                                                                    uploadedNUM ++;
//
//                                                                } else {
//                                                                    Toast.makeText(mContext, "图片"+ position1 +"上传失败。", Toast.LENGTH_SHORT).show();
//                                                                }
//                                                            }
//
//                                                            @Override
//                                                            public void getHttpProgress(int progress) {
//                                                                Log.i("上传进度:",String.valueOf(progress));
//                                                                imageModel.setProgress(progress / 10);
//                                                                mAdapter.notifyDataSetChanged();
//                                                            }
//                                                        });
                                                    } catch (Exception e) {
                                                        e.printStackTrace();
                                                    }

                                                }
                                            }.start();
                                            //ImageLoader需要的路径
                                            //final String imageurl = "file://" + chatpath + savePath;
                                            final String imageurl = "file://" + items.get(i).path;

                                            imageModel.setUrl(imageurl);
                                            imageModelList.add(imageModel);

                                            String F_GUID = "";
                                            if (dataSetComponent instanceof JSONFormModel)
                                                F_GUID = ((JSONFormModel)dataSetComponent).getFormDataModel().getBIZ_GUID();

                                            affixObject.putString("F_GUID", F_GUID);
                                            int F_ORDE = f_CodeIndex++;
                                            affixObject.putString("F_ORDE", F_ORDE + "");
                                            affixObject.putString("F_CCLX", "DB");
                                            affixObject.putString("F_NAME", "无文件名");
                                            affixObject.putString("F_FLFCT", "");
                                            affixObject.putString("F_FLBH", "");
                                            affixObject.putString("F_WJLX", "6");
                                            //affixObject.putString("F_PATH", url);
                                            affixObject.putString("F_USER", "");
                                            affixObject.putString("F_SIZE", "0");
                                            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd " + "HH:mm:ss");
                                            //设置日期格式
                                            affixObject.putString("F_CRDATE", df.format(new Date()));
                                            affixObject.putString("EXT_STR01", "");
                                            affixObject.putString("EXT_STR02", "");
                                            affixObject.putString("EXT_STR03", "");
                                            affixObject.putString("EXT_STR04", "");
                                            affixObject.putString("EXT_STR05", "");
                                            affixObject.putString("F_PATH", "");

                                            if (dataSetComponent instanceof JSONFormModel) {
                                                //将其插入到队列尾部
                                                affixDataSet.insertRowSet(imageModelList.size()-1,affixObject);
                                            }


                                        }
                                        recyclerView.scrollToPosition(imageModelList.size());
                                        if(mAdapter!=null)
                                        mAdapter.notifyDataSetChanged();
                                    } else {
                                        /**未选择图片**/
                                    }
                                }
                            });
                } else {

                    //点击图片后会进入预览界面，预览界面可以删除image，此处观察者模式，用于刷新界面，刷新dataset or db table。
                    GalleryActivity.addImageSelectorRecycleListener(FormAffixServerButton.this);

                    Intent intent = new Intent(mContext, GalleryActivity.class);
                    intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url", imageModelList.get(position).getUrl());
                    intent.putExtra("ID", position);
                    mContext.startActivity(intent);
                }
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

    }

    private void initEFDataSet() {
        if (dataSetComponent == null) return;
        if (dataSetComponent instanceof JSONFormModel) {
            affixDataSet = ((JSONFormModel) dataSetComponent).getFormDataModel().getDataSet
                    (dataSetID);
        }

        if (affixDataSet == null) {
            affixDataSet = EFDataSet.getInstance(dataSetID);
            String[] primeKey = new String[]{"F_ORDE"};
            affixDataSet.setPrimeKey(primeKey);
            ((JSONFormModel) dataSetComponent).getFormDataModel().setDataSet(dataSetID,
                    affixDataSet);
        } else {
            //有默认的图片
            List<ESPRowSet> rowSetList = affixDataSet.getRowSetList();
            if (rowSetList == null) return;
            //得到最后的F_ORDE
            ESPRowSet lastESPRowSet = rowSetList.get(rowSetList.size()-1);
            //得到默认的队列尾部的F_CODE方便后面在此基础上+1;
           String F_ORDE =  lastESPRowSet.getString("F_ORDE","");
            if(!F_ORDE.equals("")){
                try{
                    f_CodeIndex = Integer.parseInt(F_ORDE);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

            for (int i = 0; i < rowSetList.size(); i++) {
                ESPRowSet espRowSet = rowSetList.get(i);
                String F_PATH = espRowSet.getString("F_PATH", "");
                ImageModel imageModel = new ImageModel();
                imageModelList.add(imageModel);
                //F_PATH 有可能是空的，所以过滤下。
                if (!F_PATH.equals("")) {
                    imageModel.setUrl(F_PATH);
                    imageModel.setProgress(100);
                    f_CodeIndex++;
                }
            }
            if (mAdapter != null)
                mAdapter.notifyDataSetChanged();
        }

    }

    /****************
     * 数据相关
     *******************/
    public void dataChanged(EFDataSet dataSet) {
        // initEFDataSet();
        if (affixDataSet != null) {
            //urlList = affixDataSet.getRowSetList();
            if (mAdapter != null)
                mAdapter.notifyDataSetChanged();
        }
    }

    //-------------------------------------------------------
    // 基本属性
    //-------------------------------------------------------
    private String id;
    private float x = 0;
    private float y = 0;
    private int width;
    private int height;
    private Boolean visible;
    private int tabIndex = 0;

    private int percentWidth;

    private int percentHeight;

    private DataSetComponent dataSetComponent;

    private String dataSetID = "SYS_MDL_AFFIX";

    private String affixWinTitle;
    private String affixWinWidth;
    private String affixWinHeight;
    private String affixLabel;
    private String storageType;
    private String storagePath;
    private String affixMaxSize;
    private String affixType;
    private boolean isSwing;
    private boolean showPreview;
    private boolean showUploadBtn;
    private boolean showDownloadBtn;
    private boolean showDeleteBtn;
    private boolean showPhotoBtn;
    private boolean clickPreview;
    private boolean isConvert2PDF;
    private boolean isConvert2SWF;
    private boolean isConvert2HTML;
    private boolean excel03To07;
    private int preImageWinW;

    /****************
     * 样式相关
     *******************/

    @Override
    public void setID(String id) {
        this.id = id;
    }


    @Override
    public int getGap() {
        return gap;
    }

    @Override
    public void setGap(int gap) {
        this.gap = gap;
    }


    @Override
    public ViewSize getViewSize() {
        return size;
    }

    @Override
    public void setViewSize(ViewSize size) {
        this.size = size;
    }

    @Override
    public String getEditMask() {
        return null;
    }

    @Override
    public void setEditMask(String editMask) {
    }

    @Override
    public void setCompWidth(int width) {
        this.width = width;
    }

    @Override
    public int getCompWidth() {
        return this.width;
    }

    @Override
    public void setCompHeight(int height) {
        this.height = height;
    }

    @Override
    public int getCompHeight() {
        return this.height;
    }

    @Override
    public void setPercentWidth(int percentW) {
        percentWidth = percentW;
    }

    @Override
    public int getPercentHeight() {
        return percentHeight;
    }

    @Override
    public void setPercentHeight(int percentH) {
        percentHeight = percentH;
    }

    public String getHorizontalAlign() {
        return horizontalAlign;
    }

    public void setHorizontalAlign(String horizontalAlign) {
        this.horizontalAlign = horizontalAlign;
    }

    public String getVerticalAlign() {
        return verticalAlign;
    }

    public void setVerticalAlign(String verticalAlign) {
        this.verticalAlign = verticalAlign;
    }


    @Override
    public void setY(float y) {
        this.y = y;
    }


    public void setWidth(int width) {
        this.width = width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getAffixWinTitle() {
        return affixWinTitle;
    }

    public void setAffixWinTitle(String affixWinTitle) {
        this.affixWinTitle = affixWinTitle;
    }

    public String getAffixWinWidth() {
        return affixWinWidth;
    }

    public void setAffixWinWidth(String affixWinWidth) {
        this.affixWinWidth = affixWinWidth;
    }

    public String getAffixWinHeight() {
        return affixWinHeight;
    }

    public void setAffixWinHeight(String affixWinHeight) {
        this.affixWinHeight = affixWinHeight;
    }

    public String getAffixLabel() {
        return affixLabel;
    }

    public void setAffixLabel(String affixLabel) {
        this.affixLabel = affixLabel;
    }


    @Override
    public DataSetComponent getDataSetComponent() {
        return dataSetComponent;
    }

    @Override
    public void setDataSetComponent(DataSetComponent dsc) {
        if (dataSetComponent != null)
            dataSetComponent.removeDMComponent(this);
        dataSetComponent = dsc;
        if (dataSetComponent != null)
            dataSetComponent.insertDMComponent(this);
    }

    public void setDataSetComponent(JSONFormModel dsc) {
        if (dataSetComponent != null)
            dataSetComponent.removeDMComponent(this);
        dataSetComponent = dsc;
        if (dataSetComponent != null)
            dataSetComponent.insertDMComponent(this);
    }

    @Override
    public void setDataSetID(String dataSetID) {
        this.dataSetID = dataSetID;
    }

    @Override
    public String getDataSetColID() {
        return dataSetColID;
    }

    @Override
    public void setDataSetColID(String dataSetColID) {
        this.dataSetColID = dataSetColID;
    }

    @Override
    public String getDataSetNameColID() {
        return null;
    }

    @Override
    public void setDataSetNameColID(String value) {

    }

    @Override
    public String getInternalDataSetID() {
        return null;
    }

    @Override
    public void setInternalDataSetID(String dataSetID) {

    }

    @Override
    public void setViewDataSetID(String viewDataSetID) {

    }

    @Override
    public String getViewDataSetID() {
        return null;
    }

    @Override
    public void setViewDataSetColID(String viewDataSetColID) {

    }

    @Override
    public String getViewDataSetColID() {
        return null;
    }

    @Override
    public void setValueDataSetColID(String valueDataSetColID) {

    }

    @Override
    public String getValueDataSetColID() {
        return null;
    }

    @Override
    public Boolean getIsUserInternalDataSetID() {
        return null;
    }

    @Override
    public void setIsUserInternalDataSetID(Boolean v) {

    }

    @Override
    public String getIdentifier() {
        return null;
    }

    @Override
    public Object getPropertyMap() {
        return null;
    }

    @Override
    public void setPropertyMap(Object value) {

    }

    @Override
    public Object getProperty(String key, Object defVal) {
        return null;
    }

    @Override
    public void setProperty(String key, Object value) {

    }

    @Override
    public int getNumberPrecision() {
        return 0;
    }

    @Override
    public void seNumberPrecision(int value) {

    }

    @Override
    public String getNumberFormat() {
        return null;
    }

    @Override
    public void setNumberFormat(String numberFormat) {

    }

    @Override
    public String getColumnType() {
        return null;
    }

    @Override
    public void setColumnType(String value) {

    }

    @Override
    public String getEditorType() {
        return null;
    }

    @Override
    public void setEditorType(String value) {

    }

    @Override
    public String getDateFormat() {
        return null;
    }

    @Override
    public void setDateFormat(String dateFormat) {

    }

    @Override
    public String getFormulaOne() {
        return null;
    }

    @Override
    public void setFormulaOne(String formulaOne) {

    }

    @Override
    public String getFkeyID() {
        return null;
    }

    @Override
    public void setFkeyID(String fkey) {

    }

    @Override
    public String getRlglID() {
        return null;
    }

    @Override
    public void setRlglID(String rlglID) {

    }

    @Override
    public String getDataSetID() {
        return dataSetID;
    }

    @Override
    public void setDataSet(EFDataSet dataSet) {
        initEFDataSet();
        if (affixDataSet != null) {
            affixDataSet.addDataSetListener(this);

        }

    }

    @Override
    public EFDataSet getDataSet() {
        return affixDataSet;
    }

    @Override
    public EFRowSet getMainRowSet() {
        return mainRowSet;
    }


    /**
     * 目前只支持清空，不支持修改内容，不支持增加rowset、删除rowset。只能通过脚本实现。原因（两个数据集，不好控制）
     * @param event
     */
    @Override
    public void dataSetChanged(DataSetEvent event) {
        if (affixDataSet != null) {
            //urlList.clear();
            List<ESPRowSet> rowSetList = affixDataSet.getRowSetList();
            if(rowSetList==null||rowSetList.size()==0) {//清空数据
                imageModelList.clear();
            }
            if (mAdapter != null)
                mAdapter.notifyDataSetChanged();
        }

    }

    /**
     * 给组件清空数据集的方法，方便脚本使用。
     */
    public  void clear() {
        if (affixDataSet != null) {
            List<ESPRowSet> rowSetList = affixDataSet.getRowSetList();
                while(rowSetList!=null&&rowSetList.size()>0){
                 //affixDataSet没有找到清空rowset的方法。
                 if(rowSetList.size()==1) {
                     affixDataSet.removeRowSet(0);
                 }else{
                     rowSetList.remove(rowSetList.size()-1);
                 }
            }
        }

    }
    /**
     *判断是否为null
     */

    public boolean isNUll(){
        if(affixDataSet==null)
            return true;
        if(affixDataSet.getRowSetList()==null||affixDataSet.getRowSetList().size()==0)
            return true;
        return  false;
    }
    /**
     * 是否上传完
     * @return
     */
    public boolean isUpLoadOver(){
        boolean isGoon = true;
        if(uploadedNUM==uploadingNUM){
        }else{
            return  false;
//            new AlertDialog.Builder(AppContext.getCurrentActivity()).setMessage("您有图片没有上传成功，您确定要继续吗").setTitle("提示")
//                    .setNegativeButton("R.string.common_text_cancel", new DialogInterface.OnClickListener() {
//                          @Override
//                          public void onClick(DialogInterface dialogInterface, int i) {
//                              dialogInterface.dismiss();
//                          }
//                    })
//
//                    .setPositiveButton(@string/common_text_confirm, new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialogInterface, int i) {
//
//                            dialogInterface.dismiss();
//                        }
//                    }).show();
        }
        return true;
    }
    /**
     * 监听回调
     *
     * @param positon
     */
    @Override
    public void removePosition(int positon) {
        imageModelList.remove(positon);
        uploadingNUM--;
        if(!affixDataSet.getRowSet(positon).getString("F_PATH","").equals(""))
            uploadedNUM--;
        if (affixDataSet != null)
            affixDataSet.removeRowSet(positon);
    }

    @Override
    public String getID() {
        return id;
    }

    /**
     * 独有的属性
     */

    public String getStorageType() {
        return storageType;
    }

    public void setStorageType(String storageType) {
        this.storageType = storageType;
    }

    public String getStoragePath() {
        return storagePath;
    }

    public void setStoragePath(String storagePath) {
        this.storagePath = storagePath;
    }

    public String getAffixMaxSize() {
        return affixMaxSize;
    }

    public void setAffixMaxSize(String affixMaxSize) {
        this.affixMaxSize = affixMaxSize;
    }

    public String getAffixType() {
        return affixType;
    }

    public void setAffixType(String affixType) {
        this.affixType = affixType;
    }

    public boolean isSwing() {
        return isSwing;
    }

    public void setSwing(boolean swing) {
        isSwing = swing;
    }

    public boolean isShowPreview() {
        return showPreview;
    }

    public void setShowPreview(boolean showPreview) {
        this.showPreview = showPreview;
    }

    public boolean isShowUploadBtn() {
        return showUploadBtn;
    }

    public void setShowUploadBtn(boolean showUploadBtn) {
        this.showUploadBtn = showUploadBtn;
    }

    public boolean isShowDownloadBtn() {
        return showDownloadBtn;
    }

    public void setShowDownloadBtn(boolean showDownloadBtn) {
        this.showDownloadBtn = showDownloadBtn;
    }

    public boolean isShowDeleteBtn() {
        return showDeleteBtn;
    }

    public void setShowDeleteBtn(boolean showDeleteBtn) {
        this.showDeleteBtn = showDeleteBtn;
    }

    public boolean isShowPhotoBtn() {
        return showPhotoBtn;
    }

    public void setShowPhotoBtn(boolean showPhotoBtn) {
        this.showPhotoBtn = showPhotoBtn;
    }

    public boolean isClickPreview() {
        return clickPreview;
    }

    public void setClickPreview(boolean clickPreview) {
        this.clickPreview = clickPreview;
    }

    public boolean isConvert2PDF() {
        return isConvert2PDF;
    }

    public void setConvert2PDF(boolean convert2PDF) {
        isConvert2PDF = convert2PDF;
    }

    public boolean isConvert2SWF() {
        return isConvert2SWF;
    }

    public void setConvert2SWF(boolean convert2SWF) {
        isConvert2SWF = convert2SWF;
    }

    public boolean isConvert2HTML() {
        return isConvert2HTML;
    }

    public void setConvert2HTML(boolean convert2HTML) {
        isConvert2HTML = convert2HTML;
    }

    public boolean isExcel03To07() {
        return excel03To07;
    }

    public void setExcel03To07(boolean excel03To07) {
        this.excel03To07 = excel03To07;
    }

    public int getPreImageWinW() {
        return preImageWinW;
    }

    public void setPreImageWinW(int preImageWinW) {
        this.preImageWinW = preImageWinW;
    }

    public String getImageFillMode() {
        return imageFillMode;
    }

    public void setImageFillMode(String imageFillMode) {
        this.imageFillMode = imageFillMode;
    }

    public int getPhotoWinW() {
        return photoWinW;
    }

    public void setPhotoWinW(int photoWinW) {
        this.photoWinW = photoWinW;
    }

    public int getPhotoWinH() {
        return photoWinH;
    }

    public void setPhotoWinH(int photoWinH) {
        this.photoWinH = photoWinH;
    }

    private String imageFillMode;
    private int photoWinW;
    private int photoWinH;
    private int gap;

    private ViewSize size = new ViewSize(0, 0);


    private String dataSetColID;

    private String horizontalAlign;
    private String verticalAlign;


    private EFDataSet affixDataSet;
    private EFDataSet dataSet;
    private EFRowSet mainRowSet;


    private boolean isEditAble = true;

    public int getPercentWidth() {
        return percentWidth;
    }

    public void setId(String id) {
        this.id = id;
    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }


    public Boolean getVisible() {
        return visible;
    }

    public void setVisible(Boolean visible) {
        this.visible = visible;

    }

    public int getTabIndex() {
        return tabIndex;
    }

    public void setTabIndex(int tabIndex) {
        if (tabIndex != -1) {
            this.tabIndex = tabIndex;
        }
    }

    //临时方法。
    public int dp2px(float dp) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }


    public boolean isEditAble() {
        return isEditAble;
    }

    public void setEditAble(boolean editAble) {
        isEditAble = editAble;
        mAdapter.setShowAddButton(isEditAble);
    }

    @Override
    public IUIComponent getParentComp() {
        return parentComp;
    }

    @Override
    public void setParentComp(IUIComponent comp) {
        parentComp = comp;
    }

    @Override
    public void setLayout() {
        FormCompUtil.setLayoutSize(this);
        this.setGravity(FormCompUtil.getLayoutGravity(horizontalAlign, verticalAlign));
    }
}